package com.example.sls.controller.logistics;

import com.example.sls.pojo.logistics.Equipment;
import com.example.sls.service.intserfaces.logistics.EquipmentService;
import com.example.sls.utils.LogUtil;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 设备表(Equipment)表控制层
 *
 * @author 蓝江富
 * @since 2024-06-19 13:23:44
 */
@RestController
@RequestMapping("logistics/equipment")
public class EquipmentController {
  @Autowired
  EquipmentService equipmentService;

  @InitBinder
  public void initDateFormate(WebDataBinder dataBinder) {
    dataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
  }

  @GetMapping("queryById")
  Equipment queryById(Integer id) {
    return equipmentService.queryById(id);
  }

  @GetMapping("queryAllByLimit")
  List<Equipment> queryAllByLimit(Equipment equipment, Integer pageSize, Integer offset) {
    return equipmentService.queryAllByLimit(equipment, pageSize, offset);
  }

  @GetMapping("queryAll")
  List<Equipment> queryAllBy() {
    return equipmentService.queryAllByLimit(new Equipment(), 999999, 0);
  }

  @GetMapping("count")
  long count() {
    return equipmentService.count();
  }

  @GetMapping("insert")
  int insert(Equipment equipment) {
    LogUtil.log(equipment);
    return equipmentService.insert(equipment);
  }

  @GetMapping("update")
  int update(Equipment equipment) {
    return equipmentService.update(equipment);
  }

  @GetMapping("deleteById")
  int deleteById(Integer id) {
    return equipmentService.deleteById(id);
  }
}

